﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.CMS.Message.model;
using TRPOP.Common;
using System.Web;

namespace TRPOP.CMS.Message.UI
{
    /// <summary>
    /// 添加留言的逻辑代码处理
    /// </summary>
    public class MessageAdd : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            MessageInfo oMessage = new MessageInfo();

            oMessage.ntMessageContent = RequestHelper.RequestString("MessageContent");//留言内容必填
            if (oMessage.ntMessageContent.IsEmpty())
            {
                context.Response.Write("MessageNull");
                context.Response.End();
                return;
            }

            oMessage.nvcMessageTitle = RequestHelper.RequestString("MessageTitle");

            oMessage.bIsDelete = false;
            oMessage.dtCreationTime = DateTime.Now;
            oMessage.ntExtendProperty = string.Empty;
            oMessage.iContactGender = RequestHelper.RequestInt("ContactGender");
            oMessage.iMessageSend = RequestHelper.RequestInt("MessageSend");

            oMessage.iMessageStatusID = RequestHelper.RequestInt("MessageStatusID");
            if (oMessage.iMessageStatusID <= 0)
                oMessage.iMessageStatusID = 1;

            oMessage.iMessageTypeID = RequestHelper.RequestInt("MessageTypeID");
            if (oMessage.iMessageTypeID <= 0)
                oMessage.iMessageTypeID = 1;

            oMessage.nvcContactAddress = RequestHelper.RequestString("ContactAddress");

            oMessage.nvcContactEmail = RequestHelper.RequestString("ContactEmail");

            oMessage.nvcContactMobile = RequestHelper.RequestString("ContactMobile");

            oMessage.nvcContactName = RequestHelper.RequestString("ContactName");

            oMessage.nvcContactPhone = RequestHelper.RequestString("ContactPhone");

            oMessage.nvcContactPostCode = RequestHelper.RequestString("ContactPostCode");

            oMessage.nvcMessageSend = RequestHelper.RequestString("nvcMessageSend");

            if (MessageAccess.GetInstance().SaveMessage(oMessage))
            {
                context.Response.Write("OK");
                context.Response.End();
            }
            else
            {
                context.Response.Write("Error");
                context.Response.End();
            }

        }


        public bool IsReusable
        {
            get { return true; }
        }
    }
}
